<template>
  <div class="app-container" v-loading="loading">
    <!-- 添加或修改菜谱对话框 -->
    <el-form
      ref="form"
      :model="form"
      :rules="rules"
      label-width="80px"
      class="el-form"
    >
      <div class="disp-from-flxe">
        <el-form-item label="学校" prop="schoolId">
          {{ form.schoolName }}
          <!-- <el-select v-model="form.schoolId" filterable>
            <el-option
              v-for="(item, index) in schoolArr"
              :key="index"
              :label="item.nickName"
              :value="item.userId"
            ></el-option>
          </el-select> -->
        </el-form-item>
        <el-form-item label="供应商" prop="userId">
          {{ form.companyName }}
          <!-- <el-select v-model="form.userId" filterable>
            <el-option
              v-for="(item, index) in entArr"
              :key="index"
              :label="item.nickName"
              :value="item.userId"
            ></el-option>
          </el-select> -->
        </el-form-item>
      </div>

      <div class="disp-from-flxe">
        <el-form-item label="配送时间" prop="sendTime">
          {{ form.sendTime }}
        </el-form-item>
        <el-form-item label="订单" prop="money">
          {{ form.deliveryId }}
          <!-- <el-input-number
            v-model="form.money"
            :min="0"
            :precision="2"
            @change="cheNumMoney"
          ></el-input-number> -->
        </el-form-item>
      </div>

      <div class="disp-from-flxe">
        <el-form-item label="材料清单">
          <el-table border :data="form.details">
            <!-- <el-table-column type="selection" width="55" align="center" /> -->
            <el-table-column
              label="序号"
              align="center"
              type="index"
              width="50"
            />

            <el-table-column
              label="商品"
              align="center"
              width="200"
              prop="typeName"
            >
            </el-table-column>
            <el-table-column
              label="规格"
              align="center"
              width="200"
              prop="specName"
            >
            </el-table-column>
            <el-table-column
              label="单位"
              align="center"
              width="200"
              prop="brandName"
            >
            </el-table-column>

            <el-table-column label="数量" align="center" prop="num">
            </el-table-column>

            <el-table-column label="实收数量" align="center" prop="shouNum">
            </el-table-column>
            <el-table-column
              label="实际数量"
              align="center"
              width="200"
              prop="realNum"
            >
              <template slot-scope="scope">
                <el-input-number
                  v-if="form.status == 2"
                  v-model="scope.row.realNum"
                  :min="0"
                  @change="(e) => cheNum(e, scope)"
                />
                <span v-else>{{ scope.row.realNum }}</span>
              </template>
            </el-table-column>
          </el-table>
        </el-form-item>
      </div>

      <div class="disp-from-flxe">
        <el-form-item label="状态" prop="schoolId">
          <!-- {{
           form.status == 0
              ? "未验收"
              :form.status == 1
              ? "已验收"
              : "待审核"
          }} -->

          <el-tag
            :type="
              form.status == 0
                ? 'warning'
                : form.status == 1
                ? ''
                : 'info'
            "
            >{{
              form.status == 0
                ? "未验收"
                : form.status == 1
                ? "已验收"
                : "待审核"
            }}</el-tag
          >
        </el-form-item>
      </div>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="cancel">取 消</el-button>
      <el-button type="primary" @click="submitForm" v-show="form.status == 2"
        >确定审核</el-button
      >
    </div>
  </div>
</template>
    
    <script>
import { getCheckInfo, editCheck } from "@/api/system/check_accept";

export default {
  name: "addMenu",
  props: {
    mId: {
      type: String,
      default: 0,
    },
  },
  data() {
    return {
      loading: true,
      typeArr: [], //类型
      brandArr: [], //单位
      specArr: [], //规格
      schoolArr: [], //学校
      entArr: [], //供应商
      caseArrs: [
        { val: 0, lab: "小学" },
        { val: 1, lab: "初中" },
      ],
      // 表单参数
      form: {
        id: undefined,
        schoolId: undefined,
        userId: undefined,
        sendTime: undefined,
        money: 0,
        params: {
          details: [
            // {
            //   typeId: undefined, //分类id
            //   specId: undefined, //规格id
            //   brandId: undefined, //单位id
            //   price: undefined, //单价
            //   num: undefined, //数量
            //   money: 0, //总价
            //   id: undefined,
            // },
          ],
        },
      },
      // 表单校验
      rules: {
        name: [{ required: true, message: "名称不能为空", trigger: "blur" }],
        cate: [
          {
            required: true,
            message: "请选择类型",
            trigger: ["blur", "change"],
          },
        ],
        // param
      },
    };
  },
  created() {
    this.show();
    console.log(this.mId);
    console.log("this.mId");
    // console.log(this.mId)
  },
  methods: {
    cheNumMoney(e) {
      if (e == undefined) {
        e = 0.0;
        this.form.money = 0.0;
        // console.log(this.form.money)
        this.$forceUpdate();
        // form.money
      }
    },
    chType(e, scope) {
      console.log(e);
      console.log(scope);
    },
    cheNum(e, scope) {
      if (e == undefined) {
        scope.row.realNum = 0;
      }
    },
    show() {
      getCheckInfo(this.mId).then((response) => {
        this.loading = false;

        // var res = response.data;
        this.form = response.data;
      });
      if (this.mId != 0) {
      }
    },
    delParams(scope) {
      //   console.log(scope);
      this.form.params.details.splice(scope.$index, 1);
    },
    addParams(scope) {
      this.form.params.details.push({
        typeId: this.typeArr[0].id, //分类id
        specId: this.typeArr[0].specId, //规格id
        brandId: this.typeArr[0].brandId, //单位id
        price: 0, //单价
        num: 0, //采购数量
        money: 0, //总价
        remark: undefined, //备注
        jMoney: 0, //收货均价
        shouNum: 0, //已收数量
        weiNum: 0, //未收货数量
        id: undefined,
      });
      //   console.log(scope);
    },
    cancel() {
      this.$emit("cancel");
    },
    /** 提交按钮 */
    submitForm: function () {
      this.form.status = 1;
      editCheck(this.form).then((response) => {
        this.$modal.msgSuccess("修改成功");
        this.$emit("submitForm");
      });
    },
  },
};
</script>
    